﻿using System;
using System.IO;
using System.Globalization;
using System.Windows.Controls;

namespace XamlTorrent.Common.Validation
{
    public class PathValidationRule : ValidationRule
    {
        public PathValidationRule()
        {
        }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            System.Diagnostics.Trace.WriteLine(
                String.Format("PathValidationRule.Validate(\"{0}\", {1})", value, cultureInfo)
                );
            
            try
            {
                new FileInfo((string)value);
                return new ValidationResult(true, null);
            }
            catch (Exception ex)
            {
                return new ValidationResult(false, ex);
            }
        }
    }
}
